/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bllInterface;

import java.io.Serializable;

/**
 *
 * @author salm
 */
public class ChatMessage implements Serializable
{
    private ChatMessage()
    {
        this.content = new ChatMessageContent();
    }
    
    private ChatMessageContent content;
    public ChatMessageContent getContent()
    {
        return content;
    }
    
    private String sender;
    public String getSender()
    {
        return sender;
    }
    
    private String receiver;
    public String getReceiver()
    {
        return receiver;
    }
    
    private boolean needToSave;
    public boolean isNeedToSave()
    {
        return this.needToSave;
    }
    
    private boolean file = false;
    public void setIsFile( boolean isFile )
    {
        this.file   =   isFile;
    }
    public boolean isFile()
    {
        return file;
    }
    
    public static ChatMessage createMessage(String sender, String content, String receiver)
    {
        ChatMessage cm = new ChatMessage();
        cm.setSender(sender);
        cm.setReceiver(receiver);
        cm.content.put(ChatMessageContent.MESSAGE_CONTENT, content);
        cm.needToSave = true;
        
        return cm;
    }
    
    public static ChatMessage createDispatchMessage(String sender, String orgSender, String content, String receiver)
    {
        ChatMessage cm = new ChatMessage();
        cm.setSender(sender);
        cm.setReceiver(receiver);
        cm.content.put(ChatMessageContent.MESSAGE_CONTENT, content);
        cm.content.put(ChatMessageContent.ORIGINAL_SENDER, orgSender);
        cm.needToSave = false;
        
        return cm;
    }

    /**
     * @param sender the sender to set
     */
    public void setSender(String sender) {
        this.sender = sender;
    }

    /**
     * @param receiver the receiver to set
     */
    public void setReceiver(String receiver) {
        this.receiver = receiver;
    }
    
    @Override
    public ChatMessage clone()
    {
        ChatMessage cloneMsg = new ChatMessage();
        cloneMsg.sender = this.sender;
        cloneMsg.receiver = this.receiver;
        cloneMsg.content = this.content;
        cloneMsg.needToSave = this.needToSave;
        cloneMsg.file = this.file;
        
        return cloneMsg;
    }
}
